package com.kelvem.saas.workbanch.ontology.waybill.controller;

import com.kelvem.saas.workbanch.core.base.BaseController;
import com.kelvem.saas.workbanch.core.exception.SaasAssert;
import com.kelvem.saas.workbanch.ontology.piaoorder.request.PiaoOrderAddressReq;
import com.kelvem.saas.workbanch.ontology.piaoorder.request.PiaoOrderReq;
import com.kelvem.saas.workbanch.ontology.waybill.model.WaybillEntity;
import com.kelvem.saas.workbanch.ontology.waybill.service.WaybillService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author kelvem
 */
@RestController
@RequestMapping("/waybill")
@Slf4j
public class WaybillController extends BaseController {

    @Resource
    private WaybillService waybillService;
    
    @RequestMapping("/duration")
    // http://localhost:9090/waybill/duration
    public Integer duration(@RequestBody PiaoOrderAddressReq address) {
        SaasAssert.notNull(address);
    
        log.info("WaybillController:match:start, address=【{}】", address);
        Integer duration = waybillService.duration(address);
        log.info("WaybillController:match:end, duration={}", duration);
        
        return duration;
    }
    
    @RequestMapping("/match")
    // http://localhost:9090/waybill/match
    public List<WaybillEntity> match(@RequestBody PiaoOrderReq order) {
        SaasAssert.notNull(order);
    
        log.info("WaybillController:match:start, order=【{}】", order);
        List<WaybillEntity> waybillList = waybillService.match(order);
        log.info("WaybillController:match:end, waybillList.size={}", waybillList.size());
        if (waybillList.size() > 0) {
            log.info("WaybillController:match:end, waybillList[0]={}", waybillList.get(0));
        }
        
        return waybillList;
    }
    
    
}
